package com.quanxi.qxaimain.model.indicators;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import lombok.Data;
import net.sf.json.JSONArray;
import org.springframework.scheduling.annotation.Async;

import java.util.*;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;

/**
 * @Author lyx
 * @create 2022/9/5 11:17
 * 批量sql返回结果
 */
@Data

public class responseIndicators {

    private Object sql_message;
    private String ind_id;
    private Object sql_result;
    private String ind_name;
    private String sql;
    private String time;

    public responseIndicators(String ind_id ,String ind_name ,String sql,indicatorsGet indicatorsGet,Pargram pargram) throws ExecutionException, InterruptedException {
       JSONObject res = indicatorsGet.getSqlresult(sql, pargram.getD1(), pargram.getD2(), pargram.getDept_code());
        this.ind_id = ind_id;
        this.ind_name = ind_name;
        this.sql =res.getString("sql") ;
        this.sql_result=res.get("sql_result");
        this.sql_message= res.get("sql_message");
        this.time=res.getString("time");

    }

   //单指标取一个
    public void setSql_result(Object sql_result) {
        try {
            JSONArray jsonArray = JSONArray.fromObject(sql_result);
            List<Map<String,Object>> mapList=(List)jsonArray;
            Map<String, Object> map = mapList.get(0);
          Iterator it = map.entrySet().iterator() ;
          while (it.hasNext())
          {
              Map.Entry entry = (Map.Entry) it.next() ;
              Object key = entry.getKey() ;
              Object value = entry.getValue() ;
              this.sql_result=value.toString();
          }
        }
        catch (Exception e){
            this.sql_result="";
        }
    }






}